<?php
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
    /**
    +----------------------------------------------------------
    * 显示首页
    +----------------------------------------------------------
    */
    public function index()
    {
        $select=M("project");
        $select_result=$select->field('pj_name')->select();
        $stuname=Session::get(C('USER_AUTH_KEY'));
        $this->assign('select',$select_result);
        $this->assign('stuname',$stuname);
        $this->display(index);
    }
    /**
    +----------------------------------------------------------
    * 判断登录
    +----------------------------------------------------------
    */
     public function checklogin()
    {
       $stu=new Model('student');
       $stu_name=isset($_POST['stu_name'])?addslashes(trim($_POST['stu_name'])):" ";
       $stu_pwd=isset($_POST['stu_pwd'])?addslashes(trim($_POST['stu_pwd'])):" ";
       $stu_ver=isset($_POST['stu_ver'])?addslashes(trim($_POST['stu_ver'])):" ";
        if(empty($stu_name))
       {
           $this->ajaxReturn('','用户名必须!',0);
       }
       elseif(empty($stu_pwd))
       {
           $this->ajaxReturn('','密码必须!',0);
       }
       elseif(empty($stu_ver))
       {

           $this->ajaxReturn('','验证码必须!',0);
       }
        ##生成认证条件
       $map['stu_name']=$stu_name;
       $map['stu_id']=array('gt',0);
       $stu_info=$stu->where($map)->select();
       if(false==$stu_info)
       {
           $this->ajaxReturn('','用户名不存在',0);
       }
       else
       {
           if($stu_info[0]['stu_name']!=$stu_name)
           {
               $this->ajaxReturn('','用户名错误',0);
           }
           if(trim($stu_info[0]['stu_pwd'])!=$stu_pwd)
           {
               $this->ajaxReturn('','密码错误',0);
           }
           Session::set(C('USER_AUTH_KEY'), $stu_name);
          
           $this->ajaxReturn('','登录成功',1);

       }

    }
  /**
    +----------------------------------------------------------
    * 显示个人中心
    +----------------------------------------------------------
    */
     public function personnal()
    {
        if(!Session::is_set(C('USER_AUTH_KEY')))
        {
         $this->assign("jumpUrl",index);
         $this->error("您无权访问，请先登录!");
        }
        else
        {
            $perreserve=M("reserve");
            $stuname=Session::get(C('USER_AUTH_KEY'));
            $result=$perreserve->query("select pj_name,tea_name,re_id,re_date,re_status from think_reserve where stu_name='$stuname'");
           
            if($result)
            {
                $this->assign('result',$result);
                $this->display();
            }
            else
            {
                $this->display();
            }
            
        }
    }


  /**
    +----------------------------------------------------------
    * 职业查询
    +----------------------------------------------------------
    */
    public function search()
    {
        $search=M('project');
        if(isset($_POST['pj_name'])&&isset($_POST['pj_grade']))
        {
            $pj_name=$_POST['pj_name'];
            $pj_grade=$_POST['pj_grade'];
            $where['pj_name']=array('like',"%$pj_name%");
            $where['pj_grade']=array('like',"%$pj_grade%");
            $map['_complex'] = $where;
            $search_result=$search->where($map)->find();
            $_SESSION['pj_name']=$search_result['pj_name'];
            $_SESSION['pj_teacher']=$search_result['pj_teacher'];
            if($search_result)
            {
                 $this->assign('search',$search_result);
                 $this->display(searchlist);
            }
            else
            {
                 $this->assign('jumpUrl','index');
                 $this->error("没有该记录，请重新查找！");
            }
          

        }
       
    }
    /**
    +----------------------------------------------------------
    * 预约处理
    +----------------------------------------------------------
    */
    public function reserve()
    {
        $res=M('reserve');
        $stuname=Session::get(C('USER_AUTH_KEY'));
        $data['stu_name']=$stuname;
        $data['pj_name']= $_SESSION['pj_name'];
        $data['tea_name']= $_SESSION['pj_teacher'];
        $data['re_date']=date("Y-m-d");
        $res_result=$res->data($data)->add();
        if($res_result)
        {
            $this->assign("jumpUrl",'index');
            $this->success("预约成功");
        }
        else
        {
             $this->assign("jumpUrl",'index');
            $this->error("预约失败,请先登录!");
        }

    }
     /**
    +----------------------------------------------------------
    * 取约
    +----------------------------------------------------------
    */
    public function delreserve()
    {
        $redel=M("reserve");
        if(isset($_GET['d_id']))
        {
            $d_id=$_GET['d_id'];
            $data['re_status']="已取约";
            $del_result=$redel->where("re_id=$d_id")->data($data)->save();
            if($del_result)
            {
                $this->assign("jumpUrl","__URL__/personnal");
                $this->success("取约成功!");
            }
        }

     }
  /**
    +----------------------------------------------------------
    * 注销session,安全退出
    +----------------------------------------------------------
    */
    public function logout()
    {
        Session::destroy(C('USER_AUTH_KEY'));
        $this->assign("jumpUrl","index");
        $this->success("退出成功");
    }

}
?>